package com.whfc.ms.api.mach.controller.v1;

import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.mach.dto.AppMachMonthDataDTO;
import com.whfc.mach.dto.MachDataStatDTO;
import com.whfc.mach.dto.MachRunDataStatDTO;
import com.whfc.mach.param.MachMonthDataParam;
import com.whfc.ms.api.mach.service.MsMachDataAnaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author sun_guodong
 * @description 设备分析接口
 * @date 2020-11-12
 */
@RestController
@RequestMapping("/ms/api/v1/mach/ana")
public class MsMachDataAnaController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsMachDataAnaService msMachDataAnaService;

    @GetMapping("/getMachInfoData")
    public Result getMachInfoData(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                  @RequestParam("deptId") Integer deptId) {
        logger.info("获取设备基本统计信息,loginer:{},deptId:{}", user.getUsername(), deptId);
        MachDataStatDTO machDataStat = msMachDataAnaService.getMachInfoData(deptId);
        return ResultUtil.success(machDataStat);
    }

    @GetMapping("/getMachRunData")
    public Result getMachRunData(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                 @RequestParam("deptId") Integer deptId) {
        logger.info("获取设备运行数据统计,loginer:{},deptId:{}", user.getUsername(), deptId);
        MachRunDataStatDTO machRunDataStatDTO = msMachDataAnaService.getMachRunData(deptId);
        return ResultUtil.success(machRunDataStatDTO);
    }

    @PostMapping("/getMonthDataListByType")
    public Result getMonthDataListByType(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                         @Validated @RequestBody MachMonthDataParam param) {
        logger.info("获取设备纬度分析数据(设备类型),loginer:{},param:{}", user.getUsername(), param.toString());
        ListData<AppMachMonthDataDTO> listData = msMachDataAnaService.getMonthDataListByType(param);
        return ResultUtil.success(listData);
    }

    @PostMapping("/getMonthDataListByCorp")
    public Result getMonthDataListByCorp(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                         @Validated @RequestBody MachMonthDataParam param) {
        logger.info("获取设备纬度分析数据(持有单位),loginer:{},param:{}", user.getUsername(), param.toString());
        ListData<AppMachMonthDataDTO> listData = msMachDataAnaService.getMonthDataListByCorp(param);
        return ResultUtil.success(listData);
    }


}
